package com.sprite.utils;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * 安全工具类
 * @author Jack
 *
 * @see com.sprite.utils.security.UtilMessageDigest
 * @deprecated
 */
public final class UtilSecurity {
	private UtilSecurity(){}
	
	/**
	 * MD5摘要计算
	 * @param str 文本
	 * @param charSet 文本字符集
	 * @return 文本摘要
	 * @see  com.sprite.utils.security.UtilMessageDigest#md5(String, String)
	 * @deprecated
	 */
	public static final String digestByMD5(String str,String charSet) {
		MessageDigest messageDigest = null;    
		try {    
			messageDigest = MessageDigest.getInstance("MD5");    
			messageDigest.reset();   
			if(charSet==null){  
				messageDigest.update(str.getBytes());  
			}else{  
				messageDigest.update(str.getBytes(charSet));    
			}             
		} catch (NoSuchAlgorithmException e) {    
		} catch (UnsupportedEncodingException e) {    
		}    

		byte[] byteArray = messageDigest.digest();    
		StringBuffer md5StrBuff = new StringBuffer();    
		for (int i = 0; i < byteArray.length; i++) {   
			md5StrBuff.append(Integer.toHexString(0xFF&byteArray[i]));    
		}    
		return md5StrBuff.toString();    
	}
}
